package pages

import (
	"github.com/GoAdminGroup/go-admin/context"
	"github.com/GoAdminGroup/go-admin/modules/db"
	"github.com/GoAdminGroup/go-admin/plugins/admin/modules/table"
	"github.com/GoAdminGroup/go-admin/template/types"
	"github.com/GoAdminGroup/go-admin/template/types/form"
	"newclub/services"
)

func GetStudentactivitiesTable(ctx *context.Context) table.Table {

	studentActivities := table.NewDefaultTable(ctx, table.DefaultConfigWithDriver("mysql"))

	info := studentActivities.GetInfo().SetFilterFormLayout(form.LayoutFilter)

	info.AddField("Id", "id", db.Int)
	info.AddField("学生", "name", db.Int).FieldJoin(types.Join{
		Field:     "student_id",
		JoinField: "id",
		Table:     "students",
	}).FieldFilterable()
	info.AddField("活动名称", "title", db.Int).FieldJoin(types.Join{
		Field:     "activity_id",
		JoinField: "id",
		Table:     "activities",
	}).FieldFilterable()
	info.AddField("角色", "role", db.Varchar)
	info.AddField("创建时间", "created_at", db.Timestamp)

	info.SetTable("student_activities").SetTitle("参加信息").SetDescription("参加信息")

	formList := studentActivities.GetForm()
	formList.AddField("Id", "id", db.Int, form.Default).
		FieldDisableWhenCreate()
	formList.AddField("学生", "student_id", db.Int, form.SelectSingle).FieldOptions(services.TransFieldOptions(services.GetStudents(), "name", "id"))
	formList.AddField("活动名称", "activity_id", db.Int, form.SelectSingle).FieldOptions(services.TransFieldOptions(services.GetActivities(), "title", "id"))
	formList.AddField("角色", "role", db.Varchar, form.SelectSingle).FieldOptions(types.FieldOptions{
		{
			Text:  "管理",
			Value: "管理",
		},
		{
			Text:  "会员",
			Value: "会员",
		},
	})
	formList.AddField("创建时间", "created_at", db.Timestamp, form.Datetime).
		FieldHide().FieldNowWhenInsert()

	formList.SetTable("student_activities").SetTitle("参加信息").SetDescription("参加信息")

	return studentActivities
}
